//
// Created by Jisam on 2024/7/18.
//
#include <bits/stdc++.h>

#define PSI pair<string,int>
#define PII pair<int,int>
#define VVI vector<vector<int>>
#define VI vector<int>
#define VS vector<string>

#define PQLI priority_queue<int, vector<int>, less<int>>
#define PQGI priority_queue<int, vector<int>, greater<int>>
#define i64 long long

using namespace std;

const int N = 1e5 + 5;
int ans;

void solve() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    if (s == t) {
        cout << "YES\n";
        return;
    }
    if (n == 1) {
        if (s != t) cout << "NO\n";
        return;
    }

    for (int i = 1; i < n; i++) {
        if (s[i] == t[i]) {
//            cerr << i << " " << j << " " << s[i] << " " << t[i] << " " << "\n";
            continue;

        }
        s[i] = ((s[i] - '0') ^ (s[0] - '0')) + '0';
    }
    if(s[0] != t[0])
        s[0] = ((s[0] - '0') ^ (s[0] - '0')) + '0';
    if (s == t) {
        cout << "YES\n";
        return;
    }
    s[0] = ((s[0] - '0') ^ (s[0] - '0')) + '0';
    for (int i = 1; i < n; i++) {
        if (s[i] == t[i]) {
//            cerr << i << " " << j << " " << s[i] << " " << t[i] << " " << "\n";
            continue;

        }
        s[i] = ((s[i] - '0') ^ (s[0] - '0')) + '0';
    }
    if(s[0] != t[0])
        s[0] = ((s[0] - '0') ^ (s[0] - '0')) + '0';
    if (s == t) {
        cout << "YES\n";
        return;
    }

    for (int i = 1; i < n; i++) {
        if (t[i] == s[i]) {
            continue;

        }
        t[i] = ((t[i] - '0') ^ (t[0] - '0')) + '0';
    }
    if(s[0] != t[0])
        t[0] = ((t[0] - '0') ^ (t[0] - '0')) + '0';

    cout << s <<" "<< t;
    if (s == t) {
        cout << "YES\n";
        return;
    }
    t[0] = ((t[0] - '0') ^ (t[0] - '0')) + '0';
    for (int i = 1; i < n; i++) {
        if (t[i] == s[i]) {
            continue;

        }
        t[i] = ((t[i] - '0') ^ (t[0] - '0')) + '0';
    }
    if(s[0] != t[0])
        t[0] = ((t[0] - '0') ^ (t[0] - '0')) + '0';
    if (s == t) {
        cout << "YES\n";
        return;
    }
    cout << "NO\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while (T--)
        solve();

    return 0;
}